<section id="widget-grid" class="">
	<div class="row">
		<article class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
			<div class="jarviswidget jarviswidget-color-blueDark" id="wid-id-0" data-widget-editbutton="false">
				<header>
					<span class="widget-icon"><i class="fa fa-table"></i></span>
					<h2>角色管理</h2>
				</header>
				<div>
					<div class="jarviswidget-editbox"></div>
					<div class="widget-body ">
						<div style="float:left;overflow-x:auto;" id="department-tree" class="ztree">
							
						</div>
					
						<div class="table-responsive" style="margin-left:200px;">
							<table class="table table-bordered" id="main-table">
								
							</table>
						</div>

						<input id="page-num" type="hidden" value="1" /> 
						<input id="page-size" type="hidden" value="10" />
						<ul id="pager" class="pagination"></ul>
					</div>
					<!-- end widgetContent -->

				</div>
				<!-- end jarvisWidgetBody -->

			</div>
			<!-- end widget -->
			<!-- end jarvisWidget -->

		</article>
		<!-- end widgetGridCol -->

	</div>
	<!-- end widgetGridRow -->

</section>
<!-- end widgetGrid -->

<script id="role_tpl" type="text/html">
	<form action="" id="role-form" class="smart-form" novalidate="novalidate" style="overflow-x: hidden;" onsubmit="return false;">
		<fieldset>
			<div class="row">
				<section class="col col-3 ">
					<label class="label col col-12">角色名称：</label>
				</section>
				<section class="col col-9 ">
					<label class="input"> 
						<input type="text" id="name" name="name" value="{{role.name}}" placeholder="角色名称">
						<input type="hidden" id="id" name="id" value="{{role.id}}">
					</label>
				</section>
			</div>

			<div class="row">
				<section class="col col-3 ">
					<label class="label col col-12">角色状态：</label>
				</section>
				<section class="col col-9 ">
					<label class="select"> <select id="status" name="status">
						<option value="1" {{if role.status == 1}}selected{{/if}}>启用</option>
						<option value="0" {{if role.status == 0}}selected{{/if}}>不可用</option>
					</select> <i></i>
					</label>
				</section>
			</div>
			
			<div class="row">
				<section class="col col-3 ">
					<label class="label col col-12">所在部门：</label>
				</section>
				<section class="col col-9 ">
					<label class="select"> <select id="departmentId" name="departmentId">
						{{each department as value i}}
							<option value="{{value.id}}" {{if value.id == role.departmentId}}selected{{/if}}>{{value.name}}</option>
						{{/each}}
					</select> <i></i>
					</label>
				</section>
			</div>
			
			<div class="row">
				<section class="col col-3 ">
					<label class="label col col-12">备注信息：</label>
				</section>
				<section class="col col-9 ">
					<label class="input"> 
						<input type="text" id="remarks" name="remarks" value="{{role.remarks}}" placeholder="备注信息">
					</label>
				</section>
			</div>

		</fieldset>

		<footer>
			<button type="button" class="btn"onClick="layer.close(layer.index);">取消</button>
			<button type="submit" class="btn btn-primary" onClick="
				{{if role.id != null}}
					Role.Update($('#role-form').serialize())
				{{else}}
					Role.Add($('#role-form').serialize())
				{{/if}}
			">保存</button>
		</footer>
	</form>
</script>

<script id="authorities_tpl" type="text/html">
<form action="" id="authority-form" class="smart-form" novalidate="novalidate" style="overflow-x: hidden;" onsubmit="return false;">
	<fieldset>
		<div class="row">
			<input type="hidden" id="roleId" name="roleId" value="{{role.id}}">
			{{each authority as value i}}
				<label class="input col col-4"> 
					<label class="checkbox">
						<input id="authorityIds" name="authorityIds" type="checkbox" placeholder="" value="{{value.id}}" {{if role.authorityIds != null &&(role.authorityIds.indexOf(value.id.toString()) >= 0 || role.authorityIds.indexOf(value.id) >= 0)}}checked{{/if}}>
						<i></i> {{value.name}} 
					</label>
				</label>
			{{/each}}
		</div>
	</fieldset>
	<footer>
		<button type="button" class="btn"onClick="layer.close(layer.index);">取消</button>
		<button type="submit" class="btn btn-primary" onClick="Role.UpdateAuthority($('#authority-form').serialize())">保存</button>
	</footer>
</form>
</script>

<script src="js/auth/role.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	$('#department-tree').departmentZtree({'callback':zTreeOnClick});
});
function zTreeOnClick(event, treeId, treeNode) {
	Role.List({'departmentId':treeNode.id});
}
</script>